package com.wb.web.controller.wwwinfo;

import com.wb.common.annotation.Anonymous;
import com.wb.common.core.controller.BaseController;
import com.wb.common.core.domain.AjaxResult;
import com.wb.common.core.page.TableDataInfo;
import com.wb.common.exception.base.BaseException;
import com.wb.common.utils.StringUtils;
import com.wb.common.vo.DeleteRequest;
import com.wb.system.domain.WwwImagesInfoEntity;
import com.wb.system.service.IWwwImagesInfoService;
import com.wb.common.vo.WwwImagesInfoModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Description TODO
 * @Date 2025/7/10 15:23
 */
@RestController
@RequestMapping("www/images/")
@Api(tags = "图片配置替换")
public class WwwImagesInfoController extends BaseController {
    @Autowired
    private IWwwImagesInfoService iWwwInfoService;

    @PostMapping("/list")
    @ApiOperation("图片配置列表")
    public TableDataInfo list(@RequestBody WwwImagesInfoModel model) {
        startPage();
        List<WwwImagesInfoEntity> list = iWwwInfoService.selectWwwInfoList(model);
        return getDataTable(list);
    }

    @PostMapping("/add")
    @ApiOperation("图片配置创建")
    public AjaxResult add(@Valid @RequestBody WwwImagesInfoEntity entity) {
        iWwwInfoService.save(entity);
        return AjaxResult.success();
    }

    @GetMapping("/getWwwInfoLeast")
    @ApiOperation("最新生效的一条图片配置详情")
    @Anonymous
    public AjaxResult getWwwInfoLeast() {
        WwwImagesInfoEntity wwwImagesInfoEntity = iWwwInfoService.getWwwInfoLeast();
        return AjaxResult.success(wwwImagesInfoEntity);
    }

    @GetMapping("/{id}")
    @ApiOperation("图片配置详情")
    public AjaxResult get(@PathVariable("id") Long id) {
        WwwImagesInfoEntity wwwInfoModel = iWwwInfoService.getWwwInfoDetail(id);
        return AjaxResult.success(wwwInfoModel);
    }

    @PostMapping("/update")
    @ApiOperation("更新图片配置")
    public AjaxResult update(@RequestBody WwwImagesInfoEntity createVO) {

        iWwwInfoService.updateWwwInfoById(createVO);
        return AjaxResult.success();
    }


    @DeleteMapping("/deleteAll")
    @ApiOperation("删除All")
    public AjaxResult deleteAll(@RequestBody DeleteRequest request) {
        iWwwInfoService.removeVideosByIds(request.getIds());
        return AjaxResult.success();
    }

    @PostMapping("/updateStatus")
    @ApiOperation("更新图片配置状态")
    public AjaxResult updateStatus(@RequestBody WwwImagesInfoEntity wwwInfoModel) {
        if (null == wwwInfoModel || StringUtils.isNull(wwwInfoModel.getId())) {
            throw new BaseException("参数对象或ID为空，更新网站状态失败");
        }
        iWwwInfoService.updateStatus(wwwInfoModel);
        return AjaxResult.success();
    }


}
